/**
 * 饿汉式单例
 */
public class SingletonDemo01 {
    //私有构造方法
    private SingletonDemo01() {
    }
    //设置为static，类初始化立即加载该对象
    private static SingletonDemo01 instance = new SingletonDemo01();

    //获取实例，没有synchronized，效率高
    public static SingletonDemo01 getInstance() {
        return instance;
    }

}

class  SingleTonTest01{
    public static void main(String[] args) {
        SingletonDemo01 instance01 = SingletonDemo01.getInstance();
        SingletonDemo01 instance02 = SingletonDemo01.getInstance();
        System.out.println(instance01 == instance02);  //返回true,代表同一个对象
    }
}
